/*
 * PackageManagerGUI.java
 */
package org.expath.pkg.exist;

import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class PackageManagerGUI
        extends SingleFrameApplication
{
    /**
     * At startup create and show the main frame of the application.
     */
    @Override
    protected void startup()
    {
        PackageManagerGUIView view = new PackageManagerGUIView(this);
        JFrame frame = view.getFrame();
        frame.addWindowListener(new MainFrameListener());
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        show(view);
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override
    protected void configureWindow(Window root)
    {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of PackageManagerGUI
     */
    public static PackageManagerGUI getApplication()
    {
        return Application.getInstance(PackageManagerGUI.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args)
    {
        launch(PackageManagerGUI.class, args);
    }

    /**
     * To exit on closing the window.
     */
    private class MainFrameListener
            extends WindowAdapter
    {
        @Override
        public void windowClosing(WindowEvent e)
        {
            exit(e);
        }
    }
}
